package com.juc.learn.map;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * ClassName:ThreadDemo
 * Package:com.juc.learn.map
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/27 - 9:14
 * @Version:v1.0
 */
public class ThreadDemo {
    public static void main(String[] args) {
        //Map<String,Integer> map = new HashMap<>();//存在线程安全的问题
        Map<String,Integer> map = new ConcurrentHashMap<>();
        for (int i = 0; i < 150; i++) {
            new Thread(()->{
                map.put(UUID.randomUUID().toString().substring(0,4),UUID.randomUUID().hashCode()%10);
                System.out.println(map);
            }).start();
        }
    }
}
